package com.lb.jwitter.action;


import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.List; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblThongTinHocVienDTB;
import com.lb.jwitter.service.TblThongTinHocVienDTBService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblThongTinHocVientblThongTinHocVienDTBSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id ;
   }
    public void setId(int id) {
       this.id = id;
    }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
  }

    public int getHocVienId() {
       return hocVienId;
  }

    private String maHocKy; 
    public void setMaHocKy(String maHocKy) {
       this.maHocKy = maHocKy;
   }

    public String getMaHocKy() {
       return maHocKy;
   }

    private double diem; 
    public void setDiem(double diem) {
       this.diem = diem;
   }

    public double getDiem() {
       return diem;
   }

    private double dTBTichLuy; 
    public void setDTBTichLuy(double dTBTichLuy) {
       this.dTBTichLuy = dTBTichLuy;
   }

    public double getDTBTichLuy() {
       return dTBTichLuy;
   }

    private double dTBTichLuyNganh; 
    public void setDTBTichLuyNganh(double dTBTichLuyNganh) {
       this.dTBTichLuyNganh = dTBTichLuyNganh;
   }

    public double getDTBTichLuyNganh() {
       return dTBTichLuyNganh;
   }

    private double tCTL; 
    public void setTCTL(double tCTL) {
       this.tCTL = tCTL;
   }

    public double getTCTL() {
       return tCTL;
   }

    private double tCTLNganh; 
    public void setTCTLNganh(double tCTLNganh) {
       this.tCTLNganh = tCTLNganh;
   }

    public double getTCTLNganh() {
       return tCTLNganh;
   }

    private List<TblThongTinHocVienDTB> tblThongTinHocVienDTBs; 
    public List<TblThongTinHocVienDTB>  getTblThongTinHocVienDTBs() {
        return tblThongTinHocVienDTBs; 
      } 

    private TblThongTinHocVienDTBService tblThongTinHocVienDTBService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_ThongTin_HocVien_DTB", "xem")){ 
        return "noprivilege"; 
    }        tblThongTinHocVienDTBService = (TblThongTinHocVienDTBService) context.getBean("tbl_ThongTin_HocVien_DTBClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
    if(id != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("id");
        con.setValue1(id);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(hocVienId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hocVienId.id");
        con.setValue1(new Long(hocVienId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(maHocKy != null && !maHocKy.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("maHocKy");
        con.setValue1(maHocKy);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(diem != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("diem");
        con.setValue1(diem);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(dTBTichLuy != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("dTBTichLuy");
        con.setValue1(dTBTichLuy);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(dTBTichLuyNganh != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("dTBTichLuyNganh");
        con.setValue1(dTBTichLuyNganh);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(tCTL != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("tCTL");
        con.setValue1(tCTL);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(tCTLNganh != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("tCTLNganh");
        con.setValue1(tCTLNganh);
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblThongTinHocVienDTBs = tblThongTinHocVienDTBService.findtblThongTinHocVienDTBByCondition(cons,pageSize,page); 
           pages = tblThongTinHocVienDTBService.counttblThongTinHocVienDTBByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      dataString += "&id=" + id; 
      dataString += "&hocVienId=" + hocVienId; 
      dataString += "&maHocKy=" + maHocKy; 
      dataString += "&diem=" + diem; 
      dataString += "&dTBTichLuy=" + dTBTichLuy; 
      dataString += "&dTBTichLuyNganh=" + dTBTichLuyNganh; 
      dataString += "&tCTL=" + tCTL; 
      dataString += "&tCTLNganh=" + tCTLNganh; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_ThongTin_HocVien_DTB Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
